﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Web
{
    public partial class tile : System.Web.UI.Page
    {
        string strURL = "http://odds.fun88.com/";
        string strHtml = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {             
                Tile(dropEPL.SelectedValue.Trim(),dropEPL.SelectedItem.Text);             
            }
            catch (Exception ex)
            {
                
                throw ex; 
            }
        }

        void Tile(string value, string text)
        {           
            StreamReader StreamHandler;
            XmlDocument xmlDoc = new XmlDocument();            
            HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(strURL);
            wRequest.Headers.Add("Man", "GET " + strURL);
            HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
            if (wRequest.HaveResponse)
            {
                if (wResponse.StatusCode == HttpStatusCode.OK)
                {
                    StreamHandler = new System.IO.StreamReader(wResponse.GetResponseStream());
                    xmlDoc.LoadXml(StreamHandler.ReadToEnd());
                }
            }
            XmlNodeList list = xmlDoc.SelectNodes("//match[@ge='" + value + "']");
            int count = 0;            
            strHtml += "<tr style=\"background:#ddd;color:#000;font-weight:bold;\">";
            strHtml += "<td width=\"75%\" rowspan=\"2\" colspan=\"2\">" + text + "</td>";
            strHtml += "<td align=\"center\" colspan=\"3\" >Tỷ lệ</td>";
            strHtml += "<td align=\"center\" colspan=\"3\" style=\"display:none;\">Tỷ lệ Châu Âu</td>";
            strHtml += "</tr>";

            strHtml += "<tr style=\"background:#ddd;color:#000;font-weight:bold;\">";
            strHtml += "<td align=\"center\">Chủ</td>";
            strHtml += "<td align=\"center\">Chấp</td>";
            strHtml += "<td align=\"center\">Khách</td>";
            strHtml += "<td align=\"center\" style=\"display:none;\">Chủ</td>";
            strHtml += "<td align=\"center\" style=\"display:none;\">Hòa</td>";
            strHtml += "<td align=\"center\" style=\"display:none;\">Khách</td>";
            strHtml += "</tr>";

            foreach (XmlNode item in list)
            {
                if (count < 40)
                {
                    try
                    {
                        strHtml += "<tr style=\"height:30px;\">";
                        DateTime ngayThiDau = new DateTime();
                        try
                        {
                            CultureInfo provider = CultureInfo.InvariantCulture;
                            //ngayThiDau = DateTime.ParseExact(item.Attributes["mt"].Value, "M/d/yyyy h:mm:ss tt", provider);
                            ngayThiDau = DateTime.ParseExact(item.Attributes["mt"].Value, "M/d/yyyy h:mm:ss tt", provider);
                            strHtml += "<td align=\"center\">" + ngayThiDau + "</td>";
                        }
                        catch { }
                        strHtml += "<td><b>" + item.Attributes["he"].Value + "</b> vs " + item.Attributes["ae"].Value + "</td>";
                        xmlDoc.LoadXml(item.InnerXml);
                        XmlNodeList listTLCA = xmlDoc.SelectNodes("//odd[@t='ah']");
                        foreach (XmlNode tlca in listTLCA)
                        {
                            strHtml += "<td align=\"center\" style=\"background:#EFEFEF\">" + tlca.Attributes["h"].Value + "</b></td>";
                            strHtml += "<td align=\"center\" style=\"background:#EFEFEF\"><b>" + tlca.Attributes["o"].Value + "</b></td>";
                            strHtml += "<td align=\"center\" style=\"background:#EFEFEF\"><b>" + tlca.Attributes["u"].Value + "</b></td>";
                            break;
                        }
                        strHtml += "<td nowrap=\"\" align=\"center\" style=\"display:none;\"><b>0</b></td>";
                        strHtml += "<td nowrap=\"\" align=\"center\" style=\"display:none;\">0</td>";
                        strHtml += "<td nowrap=\"\" align=\"center\" style=\"display:none;\">0</td>";
                        strHtml += "</tr>";
                    }
                    catch { }
                    count++;
                }
            }

            ltdata.Text = strHtml;

        }       
    }
}